#pragma once
#include "../UIElement.h"
#include "../IUITextElement.h"

class UIScrollPanel;

class UICombobox : public UIElement, public IUITextElement
{
public:
	UICombobox();
	UICombobox(float xPos, float yPos);
	UICombobox(float xPos, float yPos, float width, float height);

	// Draws the element on the screen and has to be called between graphics.BeginDraw() and graphics.EndDraw()
	void __stdcall Draw(Graphics* graphics);

	using selecte_index_changed_evt = std::function<void(UIElement* sender, int index)>;
	UIScrollPanel* _get_item_panel_handle_() { return m_ItemScrollPanel.get(); }

	bool RoundedCorners = true;
	float RoundCornerRadiusX = 4, RoundCornerRadiusY = 4;
	Color ArrowColor = Color::Black;

	// Adds an item to the list in the combobox
	void AddItem(std::string item);

	// Removes all items
	void ClearItems();

	// Removes an item by index
	void RemoveItem(int index);

	// Removes an item by name
	void RemoveItem(std::string item);

	// Returns the index of a currently selected item
	int GetSelectedIndex() { return m_SelectedIndex; }

	// Changes the current selected index
	void SetSelectedIndex(int index);

	// Returns item at a specified index in the combobox
	std::string GetItem(int index) { return m_Items.at(index); }

	// Returns item from the list, returns -1 if item does not exist
	int IndexOf(std::string item);

	// Returns all items as a vector
	std::vector<std::string>& GetItems() { return m_Items; }

	// Returns total number of items
	int GetItemCount() { return (int)m_Items.size(); }

	// Adds a callback event for when a new item is selected
	void AddSelectedIndexChangedEvent(selecte_index_changed_evt evt) { m_SelectedIndexChangedEvents.push_back(evt); }

private:
	void SetDefaultOptions();

	int m_SelectedIndex = 0;
	bool m_ShouldDrawItems = false;

	std::vector<std::string> m_Items;
	std::unique_ptr<UIScrollPanel> m_ItemScrollPanel;

	std::vector<selecte_index_changed_evt> m_SelectedIndexChangedEvents;
};

